package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type RoleListAllLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRoleListAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleListAllLogic {
	return &RoleListAllLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 角色-查询所有
func (l *RoleListAllLogic) RoleListAll(in *pd.Request) (*pd.UmsRoleListAllResp, error) {
	d, err := l.svcCtx.UmsRoleModel.FindAll(l.ctx)
	if err != nil {
		return nil, err
	}
	var r []*pd.UmsRoleCreateReq
	copier.Copy(&r, d)
	return &pd.UmsRoleListAllResp{List: r}, nil
}
